<div class="full-screen">
<header>
    <div class="a-bar">
        <a href="javascript:history.back()" class="a-back">
		    <i class="arr left"></i>
            <{t}>返回<{/t}>
        </a>
		<span class="a-name"><{t}>库存确认<{/t}></span>
        <div class="a-right">
        </div>
    </div>
</header>

<div class="full-padding"> 
<{if count($info) > 0}>
    <form id="order-confirm-form" action="<{link app=b2c ctl=wap_member act=do_confirm full=1}>" method="post">
	    <input type="hidden" name="business_id" value="<{$business_id}>">
		<input type="hidden" id="obj_id" name="obj_id" value="">
		<input type="hidden" id="opt" name="opt" value="all">
		<span  id="opt-box">
		<div class="operate-box">
			<input type="button" value="<{t}>全选<{/t}>" class="btn-choose" onclick="selectAll()" >
			<span class="confirm-batch"><input type="button" class="operations" value="<{t}>批量确认库存<{/t}>" style="background-color:gray;border:0;color:white;padding:5px 5px;" onclick="javascript:(0);"></span>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="10%" height="40">&nbsp;</td>
				<td width="47%"><{t}>商品编号<{/t}></td>
				<td width="43%" style="text-align:right"><{t}>数量：需确认|已确认<{/t}></td>
			</tr>
            </table>
		</div>
		</span>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <!--以下部分为一个循环-->
			<{foreach from=$info item=item}>
			<tbody class="body-recom">
				<tr>
					<td colspan="3" style="height:8px;"></td>
				</tr>
				<tr>
					<td colspan="2" style="padding-left:8px;"><input name="is_checked[]" type="checkbox" value="<{$item.obj_id}>" class="ck-grey"><b><{$item.bn}></b></td>
					<td style="padding-right:8px;">
						<dl class="inventory-num">
						<dt><{input type="text" vtype="required&&number" value=$item.quantity name="confirm_num[{$item.obj_id}]" id="confirm-{$item.obj_id}" style="width:14px;" onblur="check(this,{$item.quantity},{$item.obj_id})"}></dt>
						<dd><{$item.total_confirm_num}></dd>
						</dl>
					</td>
				</tr>
				<tr>
					<td colspan="3" style="padding-left:8px; padding-right:8px;padding-bottom:8px;">
						<input name="" type="button" value="<{t}>确认库存<{/t}>" class="btn-recomok fr" onclick="do_sbc_edit(this,'<{$item.obj_id}>')">
						<a href="#" class="none-recom"><i class="iconfont" onclick="remove_num(this,'<{$item.obj_id}>')">&#xe606;</i></a> 
						<a href="<{link app=b2c ctl='wap_member' full='1' act='recommend' arg=$item.obj_id}>" class="btn-recom"><{t}>推荐<{/t}></a> 
						<!--input name="" type="button" value="推荐" class="btn-recom"-->
						<dl class="pencent-num">
						<!--dt>%</dt-->
						<dd><{$item.cost}></dd>
						</dl>
					</td>
				</tr>
			</tbody>
			<tr>
				<td colspan="3" style="height:8px;background:#ebebeb;"></td>
			</tr>
			<{/foreach}>
		</table>
	</form>
<{else}>
    <{t}>暂无数据<{/t}>
<{/if}>
</div>
</div>

<script type="text/javascript">
(function(){
    var _form = $('order-confirm-form');
	//悬浮框
    $(window).scroll(function(e){
		if($(this).scrollTop() > 175){
			ul = '<div class="operate-box" style="position:fixed; top:0; left:0; width:94%; padding:6px 3% 0 3%; background:#fff;"><input type="button" value="<{t}>全选<{/t}>" class="btn-choose" onclick="selectAll()" ><span class="confirm-batch"><input type="button" class="operations" value="<{t}>批量确认库存<{/t}>" style="background-color:gray;border:0;color:white;padding:5px 5px;" onclick="javascript:(0);"></span><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="10%" height="40">&nbsp;</td><td width="47%"><{t}>商品编号<{/t}></td><td width="43%" style="text-align:right"><{t}>数量：需确认|已确认<{/t}></td></tr></table></div>';
			$('#opt-box').html(ul);
			but_change();
		}else{
			ul = '<div class="operate-box"><input type="button" value="<{t}>全选<{/t}>" class="btn-choose" onclick="selectAll()" ><span class="confirm-batch"><input type="button" class="operations" value="<{t}>批量确认库存<{/t}>" style="background-color:gray;border:0;color:white;padding:5px 5px;" onclick="javascript:(0);"></span><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td width="10%" height="40">&nbsp;</td><td width="47%"><{t}>商品编号<{/t}></td><td width="43%" style="text-align:right"><{t}>数量：需确认|已确认<{/t}></td></tr></table></div>';
			$('#opt-box').html(ul);
            but_change();
		}
    });
})();

function but_change(){
    if(show().length == 0){
		no_checked();
	}else{
		has_checked();
	}
}

//没有选择商品时，按钮为灰色
$('#order-confirm-form .ck-grey').on('click',function(event){
	if(show().length == 0){
		no_checked();
	}else{
		has_checked();
	}
});


//选中商品的状态为黄色
function has_checked(){
	ul = '<input type="submit" class="operations" value="<{t}>批量确认库存<{/t}>" style="background-color:#f18007;border:0;color:white;padding:5px 20px;">';
	$('#order-confirm-form .confirm-batch').html(ul);
}

//不选中时为灰色
function no_checked(){
	ul = '<input type="button" class="operations" value="<{t}>批量确认库存<{/t}>" style="background-color:gray;border:0;color:white;padding:5px 5px;" onclick="javascript:(0);">';
	$('#order-confirm-form .confirm-batch').html(ul);
}

//获取选中商品
function show(){
	var cBox = document.getElementsByName("is_checked[]");
	var idents = new Array();
	for(i = 0;i < cBox.length;i++){
		if(cBox[i].checked){
			idents.push(cBox[i].checked);
		}
	}
	return idents;
}

function remove_num(e,obj_id){
    $('#confirm-'+obj_id).val(0);
    $('#obj_id').val(obj_id);
	$('#opt').val('remove');
	$('#order-confirm-form').submit();
}

function check(obj,quantity,obj_id){
    var gc_confirm_num = $('#confirm-'+obj_id).val();
	if(isNaN(gc_confirm_num)){
	    alert("<{t}>请输入非负整数!<{/t}>");
		$('#confirm-'+obj_id).val(quantity);
		return;
	}
	var reg = /^[1-9]\d*|0$/;
	var re = new RegExp(reg);
	if (gc_confirm_num.match(re) == null) {
		alert("<{t}>请输入正确的数量!<{/t}>");
		$('#confirm-'+obj_id).val(quantity);
		return;
	} 
	if(gc_confirm_num < 0){
	    alert("<{t}>请输入非负整数!<{/t}>");
		$('#confirm-'+obj_id).val(quantity);
		return;
	}
	if(gc_confirm_num > quantity){
		alert("<{t}>请输入非负整数的数量!<{/t}>");
		$('#confirm-'+obj_id).val(quantity);
		return;
	}
}

function do_sbc_edit(e,obj_id){
    var con_num = $('#confirm-'+obj_id).val();
	$('#obj_id').val(obj_id);
	$('#opt').val('single');
    $('#order-confirm-form').submit();
}

function selectAll(){
	var arr = document.getElementsByName("is_checked[]");
	var is_checked = arr[0].checked;
	for(var i = 0;i < arr.length;i++){
	    if(is_checked){
		    arr[i].checked = false;
		}else{
		    arr[i].checked = true;
		}
	}
	if(is_checked){
	    no_checked();
	}else{
		has_checked();
	}
}
</script>